package inseniarlingua

import java.awt.BorderLayout;

transPanel = null




import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import net.miginfocom.swing.MigLayout;

application(title: 'InseniarLingua',
preferredSize: [450, 380],
pack: true,
//location: [50,50],
locationByPlatform:true,
iconImage: imageIcon('/griffon-icon-48x48.png').image,
iconImages: [
	imageIcon('/griffon-icon-48x48.png').image,
	imageIcon('/griffon-icon-32x32.png').image,
	imageIcon('/griffon-icon-16x16.png').image
])
{
	panel() {
		borderLayout()
		panel(constraints: BorderLayout.NORTH) {
			label('User: ')
			model.userCB = comboBox(items: model.words.keySet().toList(),
				selectedItem: bind('user', target: model, mutual: true),
				actionPerformed: controller.changeUser)
			label('Week: ')
			model.weekCB = comboBox(items: model.words[model.user].keySet().toList(),
				selectedItem: bind('week', target: model, mutual: true),
				actionPerformed: controller.changeWeek)
		}
		transPanel = panel(layout: new MigLayout(), constraints: BorderLayout.CENTER) {
			/*
			label('Norsk')
			label('English', constraints: 'wrap')
			model.textFields = []
			model.words[model.user][model.week].each { no, en ->
				label(no)
				model.textFields << textField(columns: 12, constraints: 'wrap')
			}
			*/
		}
		populateTransPanel()
		panel(constraints: BorderLayout.SOUTH) {
			button('Restart', actionPerformed: controller.restartAction)
			button('Finished', actionPerformed: controller.finishAction)
		}
	}
}

void populateTransPanel() {
	JPanel panel = transPanel
	panel.removeAll()
	panel.add(new JLabel('Norsk'))
	panel.add(new JLabel('English'), 'wrap')
	model.textFields = []
	model.words[model.user][model.week].each { no, en ->
		panel.add(new JLabel(no))
		def tf = new JTextField(columns: 12)
		panel.add(tf, 'wrap')
		model.textFields << tf
	}
	panel.updateUI()
}